package com.mercury.pattern._15_iterator;

import java.util.Iterator;

/**
 *
 */
public class ComputerIterator implements Iterator {

    //computerCollege中存储的是数组
    Department[] depts;

    //记录当前元素的位置
    int position = 0;

    /**
     * 构造方法
     * @param depts
     */
    public ComputerIterator(Department[] depts) {
        this.depts = depts;
    }

    @Override
    public boolean hasNext() {
        if(position >= depts.length || depts[position] == null) {
            return  false;
        }
        return true;
    }

    @Override
    public Object next() {
        return depts[position++];
    }
}